#pragma once

#include "particle_renderer.h"
#include "engine/renderer/mesh/elipse.h"

namespace kanon
{
    struct ElipseVertex
    {
        glm::vec2 pos;
        glm::vec2 center;
        glm::vec2 radius;
        glm::vec4 color;
    };

    struct ElipseBatch
    {
    private:
        friend class ElipseRenderer;
        uint32_t vao = -1;
        uint32_t vbo = -1;
        uint32_t ibo = -1;

        uint32_t max_vertices = 0;
        uint32_t max_indices = 0;
        uint32_t num_vertices = 0;
        uint32_t num_indices = 0;

        ElipseVertex* vertex_base;
        uint32_t* index_base;

    public:
        ElipseBatch(uint32_t max_elipses);
        ~ElipseBatch();
        void Begin();
        void End();
        bool Submit(const Elipse& elipse);
    };

    class ElipseRenderer
    {
    private:
        std::shared_ptr<ElipseBatch> batch;
        std::shared_ptr<Shader> shader;
        std::shared_ptr<Camera2d> camera;
    public:
        ElipseRenderer();
        void SetCamera(const std::shared_ptr<Camera2d>& cam);
        void Begin();
        void Render(const std::vector<Elipse>& elipsee);
        bool Render(const Elipse& elipse);
        void End();
        void Flush();
    };
}
